package com.yugao.fintech.draper.security.customizer;

import com.yugao.fintech.draper.security.handler.UrlAuthenticationFailureHandler;
import com.yugao.fintech.draper.security.handler.UrlAuthenticationSuccessHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.Customizer;
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2TokenEndpointConfigurer;

@RequiredArgsConstructor
public class OAuth2TokenEndpointConfigurerCustomizer implements Customizer<OAuth2TokenEndpointConfigurer> {

	/**
	 * @param oAuth2TokenEndpointConfigurer the input argument
	 */
	@Override
	public void customize(OAuth2TokenEndpointConfigurer oAuth2TokenEndpointConfigurer) {
		oAuth2TokenEndpointConfigurer.accessTokenRequestConverter(AccessTokenRequestConverterCustomizer.customizer())
			// 登录成功处理器
			.accessTokenResponseHandler(new UrlAuthenticationSuccessHandler())
			// 登录失败处理器
			.errorResponseHandler(new UrlAuthenticationFailureHandler());
	}
}
